package selenium;

import org.testng.*;
import org.testng.annotations.*;
import org.openqa.selenium.*;

public class AddFilmOnlyRequired extends selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

@Test
  public void testAddFilmOnlyRequired() throws Exception {    
	driver.get(baseUrl + "/php4dvd/");
	
	selenium.LoginTest.testLogin();    

 // Add new film with only required fields   
    
    driver.get(baseUrl + "/php4dvd/");
    
    driver.findElement(By.xpath("//a[@href='./?go=add']")).click();     
       
    WebElement Title1 = 
    driver.findElement(By.name("name"));
    Title1.click();
    Title1.sendKeys("Man of Steel");
    	    
    WebElement Year1 = 
    driver.findElement(By.name("year"));
    Year1.click();
    Year1.sendKeys("2013");  
    
    WebElement Save1 = 
    driver.findElement(By.id("submit"));
    Save1.click(); 
    
 // Check Film added     
    
    WebElement FilmTitle = 
    driver.findElement(By.xpath("//div[@id='movie']//h2"));
    Assert.assertTrue(FilmTitle.getText().equals("Man of Steel (2013)"));    
    
   }  
	

private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
  
@AfterMethod
  public static void SiteLogout() throws Exception {
	
	selenium.LogoutTest.testLogout();
	       
  }  
  
}